def method():
    _, n = map(int, input().split(' '))
    s = list(input())
    Iindex = s.index('I')
    sl = s[:Iindex]
    sr = s[-1: Iindex: -1]  # 也可以用list.reverse()方法
    for _ in range(n):
        op = input()

        if op == 'backspace' and sl:
            t = sl.pop()
            if t == '(' and sr and sr[-1] == ')':
                sr.pop() 
        elif op == 'delete' and sr:
            sr.pop() 
        elif op == '<-' and sl:
            sr.append(sl.pop())
        elif op == '->' and sr:
            sl.append(sr.pop())
    s = ''.join(sl) + 'I' + ''.join(sr[::-1])
    return s

if __name__ == '__main__':
    s = method()
    print(s)
